package com.cqc.jdk8.Jutil.stream;

import org.junit.Test;

import java.util.*;
import java.util.stream.Stream;

/**
 * 创建stream的几种方式
 */
public class StreamcCreateTest {


    /**
     * 方法1： Stream<?> stream =  Collection.stream()
     */
    @Test
    public void create1() {
        List<String> list = new ArrayList<>();
        list.add("A");
        list.add("B");
        list.add("C");

        Stream<String> stream = list.stream();
    }

    /**
     * 方法1： Stream<?> stream =   Arrays.stream(arr);
     */
    @Test
    public void create2() {
        String[] arr = {"A", "B", "C"};

        Stream<String> stream = Arrays.stream(arr);
    }

    /**
     * 方法3： Stream<?> stream =   Arrays.stream(arr);
     */
    @Test
    public void create3() {
        Stream<String> stream = Stream.of("A", "B", "C");
    }

    /**
     * 方法4： Stream<?> stream =  Stream.iterate(seed,function)
     */
    @Test
    public void create4() {
        Stream<Integer> stream = Stream.iterate(0, x -> x + 1).limit(3);
        stream.forEach(System.out::println);
    }

    /**
     * 方法5： Stream<?> stream =  Stream.generate(Supplier)
     */
    @Test
    public void create5() {
        Stream<Double> stream = Stream.generate(() -> Math.random()).limit(3);
        stream.forEach(System.out::println);
    }

    /**
     *
     */
    @Test
    public void f() {
        //顺序流转并行流
        Stream<String> stream = Stream.of("A", "B", "C").parallel();

        //创建并行流
        List<String> list = new ArrayList<>();
        list.add("A");
        list.add("B");
        list.add("C");

        Stream<String> stream2 = list.parallelStream();
    }
}
